<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.resource.ResourceComInfo" %>
<%@ page import="weaver.interfaces.zhlx.duss.utils.SrmPMPUtil" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%--OA流程节点信息项目管理平台接口回传--%>
<%
    JSONObject jsonData = new JSONObject();
    BaseBean baseBean = new BaseBean();
    RecordSet rs = new RecordSet();
    String message = "";
    String status = "success";
    String requestid = Util.null2String(request.getParameter("requestid"));
    int formid = Util.getIntValue(request.getParameter("formid"));
    formid = Math.abs(formid);
    String src = Util.null2String(request.getParameter("src"));
    String type = Util.null2String(request.getParameter("type"));
    String nodeCode = "";
    String fj = "";
    String nodeName = "";
    String nodeUser = "";
    int nextnodeid = 0;
    try {
        rs.executeQuery("select * from formtable_main_" + formid + " where requestid=?", requestid);
        if(rs.next()) {
            String lcbh = Util.null2String(rs.getString("lcbh"));
            String fqrfjsc = Util.null2String(rs.getString("fqrfjsc"));
            String spbh = Util.null2String(rs.getString("spbh"));
            String szht = Util.null2String(rs.getString("szht"));
            nodeCode += lcbh + spbh;
            fj = fqrfjsc + szht;
            ResourceComInfo comInfo = new ResourceComInfo();
            rs.executeQuery("select distinct userid,nodeid,viewtype from workflow_currentoperator\n" +
                    " where (isremark in ('0','5','7') or (isremark='4' and (viewtype=0 or viewtype=-2)))  and requestid = ?", requestid);
            while (rs.next()) {
                String userid = Util.null2String(rs.getString("userid"));
                nextnodeid = Util.getIntValue(rs.getString("nodeid"));
                String nextnodename = SrmPMPUtil.getNodebaseNodename(nextnodeid).getString("nodename");
                String lastname = comInfo.getLastname(userid);
                String name = lastname + " " + nextnodename;
                nodeName += "".equals(nodeName) ? name : "," + name;
                String workcode = comInfo.getWorkcode(userid);
                nodeUser += "".equals(nodeUser) ? workcode : "," + workcode;
            }
            JSONObject dataJson = new JSONObject();
            dataJson.put("nodeCode", nodeCode);
            dataJson.put("nodeName", nodeName);
            dataJson.put("nodeUser", nodeUser);
            dataJson.put("processId", requestid);
            JSONObject reusltJson = SrmPMPUtil.getNodebaseNodename(nextnodeid);
            String nodename = Util.null2String(reusltJson.getString("nodename"));
            String isend = Util.null2String(reusltJson.getString("isend"));
            String zt = "0";
            if ("reject".equals(src)) {
                if ("退回归档勿修改".equals(nodename)) {
                    zt = "2";
                }
            } else {
                if ("1".equals(isend)) {
                    zt = "1";
                }
            }
            dataJson.put("status", zt);
            dataJson.put("type", type);
            if (!"".equals(fj)) {
                dataJson.put("attachment", SrmPMPUtil.getImageFile(fj));
            }
            dataJson.put("source", "srm");
            baseBean.writeLog(">>>>>getSrmPMPBack>>>>>dataJson=" + dataJson);
            Map<String, Object> dataMap = new HashMap<>();
            dataMap.put("jkdymc", "getSrmPMPBack");
            dataMap.put("lcid", requestid);
            dataMap.put("dylc", requestid);
            dataMap.put("cz", src);
            JSONObject resultJson = SrmPMPUtil.processSpeed(dataJson, dataMap);
            baseBean.writeLog(">>>>>getSrmPMPBack>>>>>resultJson=" + resultJson);
            String code = Util.null2String(resultJson.getString("code"));
            if ("success".equals(code)) {
                JSONObject returnDataJson = JSONObject.parseObject(resultJson.getString("data"));
                if (!"200".equals(returnDataJson.getString("code"))) {
                    message = Util.null2String(returnDataJson.getString("message"));
                    status = "failture";
                }
            } else {
                message = Util.null2String(resultJson.getString("message"));
                status = "failture";
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    jsonData.put("status", status);
    jsonData.put("message", message);
    out.print(jsonData.toJSONString());
%>




